package com.sugar.subscribe.course.module.business.controller.app.user;

import com.sugar.subscribe.course.framework.common.pojo.CommonResult;
import com.sugar.subscribe.course.framework.security.core.util.SecurityFrameworkUtils;
import com.sugar.subscribe.course.module.business.controller.app.user.vo.AppBizUserRespVO;
import com.sugar.subscribe.course.module.business.controller.app.user.vo.AppBizUserUpdateReqVO;
import com.sugar.subscribe.course.module.business.controller.app.user.vo.BizUserWechatLoginReqVO;
import com.sugar.subscribe.course.module.business.service.user.BizUserService;
import com.sugar.subscribe.course.module.system.api.auth.dto.AppAuthDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import static com.sugar.subscribe.course.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 用户信息")
@RestController
@RequestMapping("/biz/user")
@Validated
public class AppBizUserController {

    @Resource
    private BizUserService bizUserService;

    @PostMapping("/login")
    @Operation(summary = "登录")
    @PermitAll
    public CommonResult<AppAuthDTO> login(@RequestBody @Valid BizUserWechatLoginReqVO loginReqVO) {
        return success(bizUserService.login(loginReqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "更新")
    public CommonResult<Boolean> updateUser(@Valid @RequestBody AppBizUserUpdateReqVO updateReqVO) {
        bizUserService.appUpdateUser(updateReqVO, SecurityFrameworkUtils.getLoginUserId(false));
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "查详情")
    public CommonResult<AppBizUserRespVO> getUser() {
        return success(bizUserService.appGetUser(SecurityFrameworkUtils.getLoginUserId(false)));
    }
}